CSharpTest.Net
TryAddItem Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > BTreeList<T> Class : TryAddItem Method

value
The object to use as the value of the element to add.

Glossary Item Box

Adds an element with the provided value to the IList.

Syntax

Visual Basic (Declaration) 
Public Function TryAddItem( _
   ByVal value As T _
) As Boolean
C# 
public bool TryAddItem( 
   T value
)

Parameters

value
The object to use as the value of the element to add.

Exceptions

ExceptionDescription
System.NotSupportedExceptionThe IList is read-only.

Example

Library/Library.Test/TestBTreeList.cs

C#Copy Code
BTreeList<int> data = new BTreeList<int>(Comparer);
for (int i = 0; i < 100; i++)
    Assert.IsTrue(data.TryAddItem(i));

Assert.AreEqual(50, new List<int>(data.EnumerateFrom(50)).Count);
Assert.AreEqual(25, new List<int>(data.EnumerateFrom(75)).Count);

for (int i = 0; i < 100; i++)
{
    int first = -1;
    foreach (int kv in data.EnumerateFrom(i))
    {
        first = kv;
        break;
    }
    Assert.AreEqual(i, first);
}
VB.NETCopy Code
Dim data As New BTreeList(Of Integer)(Comparer)
Dim i As Integer = 0
While i < 100
    Assert.IsTrue(data.TryAddItem(i))
    System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While

Assert.AreEqual(50, New List(Of Integer)(data.EnumerateFrom(50)).Count)
Assert.AreEqual(25, New List(Of Integer)(data.EnumerateFrom(75)).Count)

Dim i As Integer = 0
While i < 100
    Dim first As Integer = -1
    For Each kv As Integer In data.EnumerateFrom(i)
        first = kv
        Exit For
    Next
    Assert.AreEqual(i, first)
    System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys